﻿#region using
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ibba.src.norisk.DataAccess;
using ibba.src.norisk.BusinessEntities;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
#endregion

/*****************************************************************************************************************          
 Copyright © 2010 - Banco Itaú BBA S.A          
          
 InstrumentoBL : Faz acesso a classe InstrumentoBl
            
 Histórico de Alterações:      
 29/07/2010 - Leandra M. Madureira	- Criacao OS393398

 *****************************************************************************************************************/

namespace ibba.src.norisk.BusinessLogic
{
    public class InstrumentoBL
    {

        private InstrumentoDb _instrumentoDb;

        public InstrumentoBL()
        {
            _instrumentoDb = new InstrumentoDb();
        }

        public List<BusinessEntities.Instrumento> ObterInstrumento()
        {
            return (_instrumentoDb.ObterInstrumento());
        }

        public int AtualizarInstrumento(List<BusinessEntities.Instrumento> pInstrumento, string pCodUsuario)
        {
            //Tranforma a lista em xml
            XmlNodeList nodes = null;
            string sXml = "";
            XmlDocument doc = new XmlDocument();

            XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(pInstrumento.GetType());
            MemoryStream stream = new System.IO.MemoryStream();

            serializer.Serialize(stream, pInstrumento);
            stream.Position = 0;
            doc.Load(stream);

            nodes = doc.SelectNodes("//ArrayOfInstrumento");

            foreach (XmlNode node in nodes)
            {
                sXml += node.InnerXml;
            }

            doc = new XmlDocument();

            doc.LoadXml("<root>" + sXml + "</root>");

            return _instrumentoDb.AtualizarInstrumento(doc.InnerXml, pCodUsuario);
        }
    }
}